home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Pointer / c / Restrict
Text File  |  1995-07-08  |  3KB  |  84 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Pointer.Restrict.c
  12.     Author:  Copyright © 1994 Lee Atkinson
  13.     Version: 1.00 (28 Sep 1994)
  14.     Purpose: Restrict pointer to window or icon
  15. */
  16.  
  17. #include "DeskLib:Error.h"
  18. #include "DeskLib:Icon.h"
  19. #include "DeskLib:KernelSWIs.h"
  20. #include "DeskLib:Screen.h"
  21. #include "DeskLib:Wimp.h"
  22. #include "DeskLib:WimpSWIs.h"
  23. #include "DeskLib:Pointer.h"
  24.  
  25.  
  26. typedef char byte;
  27.  
  28. static void Lower2Bytes(int integer,byte *byte0,byte *byte1)
  29.                              /* extracts lowest 2 bytes from input integer */
  30. {
  31.  union
  32.       {
  33.        int integer;
  34.        byte bytes[2];
  35.       }
  36.        u;
  37.  u.integer=integer;
  38.  *byte0=u.bytes[0]; /* lowest byte */
  39.  *byte1=u.bytes[1]; /* next lowest byte */
  40. }
  41.  
  42. os_error *Pointer_RestrictToWindow(window_handle window)
  43. {
  44.  byte         box[9]={1};
  45.  window_state wstate;
  46.  Wimp_GetWindowState(window,&wstate); /* find window size & pos. */
  47.  Lower2Bytes(wstate.openblock.screenrect.min.x,&box[1],&box[2]);
  48.  Lower2Bytes(wstate.openblock.screenrect.min.y,&box[3],&box[4]);
  49.  Lower2Bytes(wstate.openblock.screenrect.max.x,&box[5],&box[6]);
  50.  Lower2Bytes(wstate.openblock.screenrect.max.y,&box[7],&box[8]);
  51.  return OS_Word(osword_DEFINEPOINTERANDMOUSE,box);
  52. }
  53.  
  54. os_error *Pointer_RestrictToIcon(window_handle window,icon_handle icon)
  55. {
  56.  byte      box[9]={1};
  57.  wimp_rect rect;
  58.  Icon_ScreenPos(window,icon,&rect);
  59.  Lower2Bytes(rect.min.x,&box[1],&box[2]);
  60.  Lower2Bytes(rect.min.y,&box[3],&box[4]);
  61.  Lower2Bytes(rect.max.x,&box[5],&box[6]);
  62.  Lower2Bytes(rect.max.y,&box[7],&box[8]);
  63.  return OS_Word(osword_DEFINEPOINTERANDMOUSE,box);
  64. }
  65.  
  66. os_error *Pointer_RestrictToRect(wimp_rect rect)
  67. {
  68.  byte box[9]={1};
  69.  Lower2Bytes(rect.min.x,&box[1],&box[2]);
  70.  Lower2Bytes(rect.min.y,&box[3],&box[4]);
  71.  Lower2Bytes(rect.max.x,&box[5],&box[6]);
  72.  Lower2Bytes(rect.max.y,&box[7],&box[8]);
  73.  return OS_Word(osword_DEFINEPOINTERANDMOUSE,box);
  74. }
  75.  
  76. os_error *Pointer_Unrestrict(void)
  77. {
  78.  byte box[9]={1,0,0,0,0};
  79.  Screen_CacheModeInfo(); /* find screen size */
  80.  Lower2Bytes((screen_size.x-1),&box[5],&box[6]);
  81.  Lower2Bytes((screen_size.y-1),&box[7],&box[8]);
  82.  return OS_Word(osword_DEFINEPOINTERANDMOUSE,box);
  83. }
  84.